package com.innovation.core;

import io.netty.channel.Channel;

import java.util.HashMap;
import java.util.Map;

import com.google.protobuf.Message;
import com.innovation.data.model.Player;
import com.innovation.message.PBMessageProto.PBMessage;
/**
 * 请求对象
 * @author Administrator
 *
 */
public class RequestSession {
	private PBMessage request = null;//请求数据
	private Channel channel = null;//连接
	private PBMessage.Builder response = null; //响应数据
	private Map<Integer, Long> logData = null; //Flow日志数据
	private long recvTime; //请求接收时间
	private Player player;
	private String result = "succ"; //命令执行结果标示
	
	
	public RequestSession(PBMessage request, Channel channel){
		this.request = request;
		this.channel = channel;
		
		//新建一个响应数据,并设置头部信息
		this.response = PBMessage.newBuilder();
		this.response.setCode(request.getCode());
		this.response.setPlayerId(request.getPlayerId());
		this.response.setSequence(request.getSequence());
		
		this.recvTime = System.currentTimeMillis();
		
		this.logData = new HashMap<Integer, Long>();
	}
	
	/**
	 * 获取操作码
	 * @return
	 */
	public int getActionCode(){
		return this.request.getCode();
	}
	
	/**
	 * 获取玩家id
	 * @return
	 */
	public int getPlayerId(){
		return this.request.getPlayerId();
	}
	
	/**
	 * 设置服务器端返回数据
	 * @param msg
	 */
	public void setResponseMsg(Message msg){
		this.response.setData(msg.toByteString());
	}

	public PBMessage getRequest() {
		return request;
	}

	public void setRequest(PBMessage request) {
		this.request = request;
	}

	public Channel getChannel() {
		return channel;
	}

	public void setChannel(Channel channel) {
		this.channel = channel;
	}

	public PBMessage.Builder getResponse() {
		return response;
	}

	public void setResponse(PBMessage.Builder response) {
		this.response = response;
	}

	public Map<Integer, Long> getLogData() {
		return logData;
	}

	public void setLogData(Map<Integer, Long> logData) {
		this.logData = logData;
	}

	public long getRecvTime() {
		return recvTime;
	}

	public void setRecvTime(long recvTime) {
		this.recvTime = recvTime;
	}

	public Player getPlayer() {
		return player;
	}

	public void setPlayer(Player player) {
		this.player = player;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}
}